CC=gcc
# OPENSSLDIR=./3rdparty/openssl-3.5-x86
#OPENSSLDIR=./3rdparty/openssl-3.5-noasm
OPENSSLDIR=./3rdparty/openssl-3.5
MBEDTLSDIR=./3rdparty/mbedtls
# MBEDTLSDIR=./3rdparty/mbedtls-3.5.0-x86
NETTLEDIR=./3rdparty/nettle-3.9-arm
# NETTLEDIR=./3rdparty/nettle-3.9-x86

CFLAGS=-g -Wall -Wno-pointer-sign -fPIC -I. -I./include -I$(OPENSSLDIR)/include -I$(MBEDTLSDIR)/include -I$(NETTLEDIR)/include -I$(OPENSSLDIR)/include
TARGET_BIN_DIR?=.
TARGET_LIB_DIR?=.

SRC_DIR=./
OBJ_DIR=./


.PHONY: tests

tests: $(TARGET_BIN_DIR)/abcrypto

SRCEXTS   := .c .S # C program
SRCDIRS= ./ ./openssl ./mbedtls ./nettle

SRCS = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
SRC_OBJS    = $(foreach x,$(SRCEXTS), \
      $(patsubst %$(x), %.o, $(filter %$(x),$(SRCS))))


$(filter %.o,$(SRC_OBJS)): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
	$(CC) $(CFLAGS) -c $< -o $@ 


$(TARGET_BIN_DIR)/abcrypto: $(SRC_OBJS)
	echo $(SRC_OBJS)
	$(CC) -static  -L$(TARGET_LIB_DIR) -L$(MBEDTLSDIR) -L$(OPENSSLDIR) -L$(NETTLEDIR)/lib -Wl,-rpath $(TARGET_LIB_DIR) \
	  $(SRC_OBJS) -o $@ -lmbedcrypto -lmbedtls -lssl -lcrypto -lnettle -lhogweed -lpthread -ldl 

clean:
	rm -f $(TARGET_BIN_DIR)/abcrypto
	rm -f $(SRC_OBJS)

